﻿namespace IP_Package.GUI
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;

    /// <summary>
    /// matlap form
    /// </summary>
    public partial class MatLapConnectOperation : Form
    {
        /// <summary>
        /// MATLAP operation object
        /// </summary>
        private Operations.MATLAP_operations.MATLAPOper matlapMagu = new Operations.MATLAP_operations.MATLAPOper();

        /// <summary>
        /// buffer of orignal image
        /// </summary>
        private Color[,] bufferOfImage;

        /// <summary>
        /// result image
        /// </summary>
        private Bitmap resultImg;

        /// <summary>
        /// Initializes a new instance of the <see cref="MatLapConnectOperation"/> class.
        /// </summary>
        public MatLapConnectOperation()
        {
            this.InitializeComponent();
        }

        /// <summary>
        /// Gets or sets the buffer of image.
        /// </summary>
        /// <value>
        /// The buffer of image.
        /// </value>
        public Color[,] BufferOfImage
        {
            get { return this.bufferOfImage; }
            set { this.bufferOfImage = value; }
        }

        /// <summary>
        /// Gets or sets the result img.
        /// </summary>
        /// <value>
        /// The result img.
        /// </value>
        public Bitmap ResultImg
        {
            get { return this.resultImg; }
            set { this.resultImg = value; }
        }

        /// <summary>
        /// Sets the type.
        /// </summary>
        /// <param name="type">The type.</param>
        public void SetType(string type)
        {
            if (type == "To Freq")
            {
                this.btSpatialDomainConvert.Visible = false;
            }
            else
            {
                this.BTConvertToFrequenceDomain.Visible = false;
            }
        }

        /// <summary>
        /// Sets the info of orignal image.
        /// </summary>
        /// <param name="image">The orginal image.</param>
        /// <param name="width">The width of orignal image.</param>
        /// <param name="height">The height of orignal image.</param>
        /// <param name="bufferOfImage">The buffer of orignal image.</param>
        internal void SetInfo(Image image, string width, string height, Color[,] bufferOfImage)
        {
            this.picOrg.Image = image;
            this.LabWdth.Text = width;
            this.LabHth.Text = height;
            this.bufferOfImage = bufferOfImage;
        }

        /// <summary>
        /// Handles the Click event of the BtSpatialDomainConvert control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void BtSpatialDomainConvert_Click(object sender, EventArgs e)
        {
            try
            {
                this.matlapMagu.BufferOfImage = this.BufferOfImage;
                Bitmap graphImg = this.matlapMagu.ConvertToSpatialDomain();
                this.resultPicBox.Image = graphImg;
            }
            catch
            {
                MessageBox.Show("no image to draw histogram or the operation invalid now");
            }
        }

        /// <summary>
        /// Handles the Click event of the BTConvertToFrequenceDomain control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void BTConvertToFrequenceDomain_Click(object sender, EventArgs e)
        {
            try
            {
               this.matlapMagu.BufferOfImage = this.BufferOfImage;
                Bitmap graphImg = this.matlapMagu.CalcuMagnitudeTOImag();
                this.resultPicBox.Image = graphImg;
            }
            catch
            {
                MessageBox.Show("no image to draw histogram or the operation invalid now");
            }
        }
        }
}
